package com.lms.time;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.Locale;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-07-01 10:13
 * @Description:
 */
public class DateTimeFormatterDemo {
    public static void main(String[] args) {

        DateTimeFormatter isoDateTime = DateTimeFormatter.ISO_DATE_TIME;
        LocalDateTime now = LocalDateTime.now();
        //2020-07-01T10:17:50.616
        System.out.println(now);
        //2020-07-01T10:17:50.616
        String format = now.format(isoDateTime);
        //2020-07-01
        String format1 = now.format(DateTimeFormatter.ISO_DATE);
        //10:17:50.616
        String format2 = now.format(DateTimeFormatter.ISO_LOCAL_TIME);
        //10:19:46.698
        String format3 = now.format(DateTimeFormatter.ISO_TIME);
        //20200701
        String format4 = now.format(DateTimeFormatter.BASIC_ISO_DATE);
        //2020-07-01T10:24:46.668
        String format5 = now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        //2020/07/01  10时 26分 02秒 052纳秒
        String format6 = now.format(DateTimeFormatter.ofPattern("yyyy/MM/dd  HH时 mm分 ss秒 SSS纳秒"));

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd  HH时 mm分 ss秒 SSS纳秒");
        TemporalAccessor parse = dateTimeFormatter.parse("2020/07/01  10时 26分 02秒 052纳秒");
        LocalDateTime from = LocalDateTime.from(parse);
        //2020 Jul 01 Wed 10:39
        String format7 = now.format(DateTimeFormatter.ofPattern("yyyy MMM dd EE HH:mm",Locale.US));
        //2020 七月 01 星期三 10:39
        String format8 = now.format(DateTimeFormatter.ofPattern("yyyy MMM dd EE HH:mm",Locale.CHINA));
    }
}
